package wine.ejb.utilities;

import java.security.MessageDigest;

/**
 * @author chg E-mail:chg85031@163.com
 * @version createDate：2008-11-27 下午03:40:47
 * @describe md方法加密
 */
public final class Md5 {

	private Md5() {
	}

	private static String byteHEX(byte ib) {
		char Digit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
				'B', 'C', 'D', 'E', 'F' };
		char ob[] = new char[2];
		ob[0] = Digit[ib >>> 4 & 0xf];
		ob[1] = Digit[ib & 0xf];
		String s = new String(ob);
		return s;
	}

	public static String encrypt(String source) {
		String s;
		try {
			MessageDigest std = MessageDigest.getInstance("MD5", "SUN");
			byte digest[] = std.digest(source.getBytes());
			String digestHexStr = "";
			for (int i = 0; i < 16; i++) {
				digestHexStr = String.valueOf(digestHexStr)
						+ String.valueOf(byteHEX(digest[i]));
			}
			String s1 = digestHexStr;
			return s1;
		} catch (Exception e) {
			s = "";
		}
		return s;
	}

	public static void main(String[] arg) {
		String s = "admin";
		String s1 = "123456";
		// System.out.print(encrypt(s));
		// System.out.print(encrypt(s1));
	}
}
